#ifndef __SHMIPC_SHM_MUTEX_H__
#define __SHMIPC_SHM_MUTEX_H__

#include <pthread.h>
#include <cstdint>

namespace shmipc::core {

class ShmCond;

class ShmMutex final {
public:
    ShmMutex();
    ~ShmMutex();
public:
    int lock();
    int unlock();

private:
    friend class ShmCond;
    pthread_mutex_t mutex_;
};

class AutoShmMutex final {
public:
    AutoShmMutex(ShmMutex& mutex):lock_(mutex) { lock_.lock(); }
    ~AutoShmMutex() { lock_.unlock(); }

public:
    void lock() { lock_.lock(); }
    void unlock() { lock_.unlock(); }
private:
    friend class ShmCond;
    ShmMutex& lock_;
};

} //namespace shmipc::core

#endif /** !__SHMIPC_SHM_MUTEX_H__ */
